package com.google.code.p.restrpc.http.entity;

import java.io.UnsupportedEncodingException;

import org.apache.http.Header;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * 
 * @author dz
 *
 */
public class JsonEntity extends StringEntity {
    
    public JsonEntity(String string, String mimeType, String charset) throws UnsupportedEncodingException {
        super(string, mimeType, charset);
    }
    
    public JsonEntity(String string, String charset) throws UnsupportedEncodingException {
        super(string, charset);
    }
    
    public JsonEntity(String string) throws UnsupportedEncodingException {
        super(string);
    }
    
    public JsonEntity(Object object, String mimeType, String charset) throws UnsupportedEncodingException {
        super(JSON.toJSONString(object, SerializerFeature.WriteClassName),
              mimeType,
              charset);
    }
    
    public JsonEntity(Object object, String charset) throws UnsupportedEncodingException {
        super(JSON.toJSONString(object, SerializerFeature.WriteClassName),
              charset);
    }
    
    public JsonEntity(Object object) throws UnsupportedEncodingException {
        super(JSON.toJSONString(object, SerializerFeature.WriteClassName));
    }
    
    public JsonEntity(JSONObject jsonObject, String mimeType, String charset) throws UnsupportedEncodingException {
        super(jsonObject.toJSONString(), mimeType, charset);
    }
    
    public JsonEntity(JSONObject jsonObject, String charset) throws UnsupportedEncodingException {
        super(jsonObject.toJSONString(), charset);
    }
    
    public JsonEntity(JSONObject jsonObject) throws UnsupportedEncodingException {
        super(jsonObject.toJSONString());
    }
    
    @Override
    public Header getContentType() {
        return new BasicHeader(HTTP.CONTENT_TYPE, "text/json");
    }
}
